/*
 * =====================================================================================
 * Copyright (C) 2024 Ingenic Semiconductor Co.,Ltd
 * All Rights Reserved
 *
 * Filename     : printk.c
 * Author       : Keven <keven.ywhan@ingenic.com>
 * Created      : 2024/06/03 15:52
 * Description  :
 *
 * =====================================================================================
 */

#include <stddef.h>
#include <stdarg.h>
#include <ctype.h>

#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "portable.h"
#include "task.h"
#include "serial.h"

static char pbuffer[4096];
extern int vsnprintf(char *buf, size_t size, const char *fmt,
		va_list args);
void printk(const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vsnprintf(pbuffer, 4096, fmt, args);
	va_end(args);

	serial_puts(configPRINT_UART_INDEX, pbuffer);
}

void *kmalloc(size_t size)
{
	return pvPortMalloc(size);
}

void kfree(void *addr)
{
	vPortFree(addr);
}

size_t get_free_heap_size(void)
{
	return xPortGetFreeHeapSize();
}

void msleep(uint32_t msecs)
{
	vTaskDelay(msecs);
}

void sleep(uint32_t secs)
{
	msleep(secs*1000);
}

